def load_1():
  talkTime = 5
  numIntrAnsChat = 0
  numIntrAnsEmail = 0
  numIntrRelChat = 0
  numIntrRelEmail = 0
  num = 5
  for i in range(0, num):
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")  
    if i == num - 1:     # last time
      time.sleep(180)       # all emails come
    else:
      time.sleep(90)
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))

    
    while 1:
      for ag in [AilAg3, AilAg4, AilAg5]:
        intrs = ag.ailAgent.getInteractions()
        for intr in intrs:
          if intr.getStatus() == ailInteractionStatus.RINGING:
            if intr.getType() in (ailInteractionType.CHAT,): 
              intr.setVisibility(ailChatVisibility.ALL)
            try:
              intr.answerCall(None) # accept email, chat for agent
              
              if intr.getType() in (ailInteractionType.CHAT,):
                numIntrAnsChat = numIntrAnsChat + 1
              elif intr.getType() in (ailInteractionType.EMAILIN,):
                numIntrAnsEmail = numIntrAnsEmail + 1
              
            except ailException.IsErrorException, mess:
              print mess  
      time.sleep(talkTime)
      released = 0
      for ag in [AilAg3, AilAg4, AilAg5]:
        intrs = ag.ailAgent.getInteractions()
        for intr in intrs:
          if intr.getStatus() in (ailInteractionStatus.TALKING, ailInteractionStatus.IDLE):
            released = 1
            if intr.getType() in (ailInteractionType.CHAT,) :
              try:
                intr.releaseCall(None)
              except ailException.IsErrorException, mess:
                print mess
            try:
              intr.markDone()
              if intr.getType() in (ailInteractionType.CHAT,):
                numIntrRelChat = numIntrRelChat + 1
              elif intr.getType() in (ailInteractionType.EMAILIN,):
                numIntrRelEmail = numIntrRelEmail + 1              
            except ailException.IsErrorException, mess:
              print mess
      if not released:
        break
  print "CHAT INTERACTIONS answered %d" %numIntrAnsChat
  print "EMAIL INTERACTIONS answered %d" %numIntrAnsEmail
  print "CHAT INTERACTIONS marked done %d" %numIntrRelChat
  print "EMAIL INTERACTIONS marked done %d" %numIntrRelEmail
  
def load_2():
  talkTime = 5
  numIntrAnsI = 0
  numIntrRelI = 0
  numIntrAns = 0
  numIntrRel = 0
  num = 20
  for i in range(0, num):
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")    
    if i == num - 1:     # last time
      time.sleep(120)       # all emails come
    else:
      time.sleep(90)
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))    
    
    while 1:
      numIntrAnsI = AcceptAllInteractionsOnAlertingAgents([AilAg3, AilAg4, AilAg5])
      numIntrAns = numIntrAns + numIntrAnsI
      if numIntrAnsI:
        time.sleep(talkTime)
      numIntrRelI = MarkDoneAllInteractionsOnTalkingAgents([AilAg3, AilAg4, AilAg5])
      numIntrRel = numIntrRel + numIntrRelI
      if not numIntrRelI:
        break
      
  print "INTERACTIONS answered %d" %numIntrAns
  print "INTERACTIONS marked done %d" %numIntrRel
 
 
def load_3():
  talkTime = 5
  numIntrAnsI = 0
  numIntrRelI = 0
  numIntrAns = 0
  numIntrRel = 0
  num = 10
  for i in range(0, num):
    for j in range(0,40): # more then N agents * capacity 
      emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
 
    
    if i == num - 1:     # last time
      time.sleep(120)       # all emails come
    else:
      time.sleep(90)
    for j in range(0,40):
      chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    
    while 1:
      numIntrAnsI = AcceptAllInteractionsOnAlertingAgents([AilAg3, AilAg4, AilAg5])
      numIntrAns = numIntrAns + numIntrAnsI
      if numIntrAnsI:
        time.sleep(talkTime)
      numIntrRelI = MarkDoneAllInteractionsOnTalkingAgents([AilAg3, AilAg4, AilAg5])
      numIntrRel = numIntrRel + numIntrRelI
      if not numIntrRelI:
        break
  while 1:
    numIntrAnsI = AcceptAllInteractionsOnAlertingAgents([AilAg3, AilAg4, AilAg5])
    numIntrAns = numIntrAns + numIntrAnsI
    if numIntrAnsI:
      time.sleep(talkTime)
    numIntrRelI = MarkDoneAllInteractionsOnTalkingAgents([AilAg3, AilAg4, AilAg5])
    numIntrRel = numIntrRel + numIntrRelI
    if not numIntrRelI:
      break      
  print "INTERACTIONS answered %d" %numIntrAns
  print "INTERACTIONS marked done %d" %numIntrRel 
 
def load_4():
  #to check stats
  talkTime = 5
  emCnt = 0
  chCnt = 0
  num = 2
  for i in range(0, num):
    #10
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    
    if i == num - 1:     # last time
      time.sleep(120)       # all emails come
    else:
      time.sleep(90)
    while 1:
      emAgs = AcceptEmailsOnAlertingAgents([AilAg3, AilAg4, AilAg5])
      chAgs = AcceptChatsOnAlertingAgents([AilAg3, AilAg4, AilAg5])
      if emAgs or chAgs:
        time.sleep(talkTime)
      else:
        break
      for ag in emAgs.keys(): 
        PrintLog("\n%s answered %d emails" %(ag, emAgs[ag]))
        emCnt = emCnt + emAgs[ag]
        mdEm = MarkDoneEmailsOnTalkingAgent(ag)
      for ag in chAgs.keys():   
        PrintLog("\n%s answered %d chats" %(ag, chAgs[ag]))
        chCnt = chCnt + chAgs[ag]
        mdCh = MarkDoneChatsOnTalkingAgent(ag)
        
  while 1:
    emAgs = AcceptEmailsOnAlertingAgents([AilAg3, AilAg4, AilAg5])
    chAgs = AcceptChatsOnAlertingAgents([AilAg3, AilAg4, AilAg5])
    if emAgs or chAgs:
      time.sleep(talkTime)
    else:
      break
    for ag in emAgs.keys(): 
      PrintLog("\n%s answered %d emails" %(ag, emAgs[ag]))
      emCnt = emCnt + emAgs[ag]
      mdEm = MarkDoneEmailsOnTalkingAgent(ag)
    for ag in chAgs.keys():   
      PrintLog("\n%s answered %d chats" %(ag, chAgs[ag]))
      chCnt = chCnt + chAgs[ag]
      mdCh = MarkDoneChatsOnTalkingAgent(ag)        
  PrintLog("Emails answered %d" %emCnt)
  PrintLog("Chats answered %d" %chCnt)
    
